/* $Header: p_column.c,v 2.3 03/06/17 10:53:16 przybyls Exp $ */

/***********************************************************************/
/*                                                                     */
/*                  Copyright Hewlett-Packard Co. 1991                 */
/*                                                                     */
/***********************************************************************/

/***********************************************************************/
/* MODULE NAME:                                                        */
/* ============                                                        */
/*                                                                     */
/* Author:                                                             */
/*                                                                     */
/* MODULE PURPOSE:                                                     */
/*                                                                     */
/*                                                                     */
/*                                                                     */
/*                                                                     */
/***********************************************************************/


/*****************************/
/*   GLOBAL INCLUDE FILES    */
/*****************************/

#include <typedefs.h>
#include <error.h>
#include <p_wkfile.h>
#include <wkfile.h>
#include <p_status.h>
#include <ramps.h>         /* needed for status.h */
#include <zone_config.h>   /* needed for status.h */
#include <zone_status.h>   /* needed for status.h */
#include <status.h>        /* definition of Oven_Table */
#include <list_mgmt.h>
#include <run_ui.h>
#include <keyboard.h>
#include <math.h>

/*****************************/
/*   LOCAL INCLUDE FILES     */
/*****************************/

#include "proto.h"
#include "p_err.h"
#include "pneu_int.h"

/*****************************/
/*   GLOBAL VARIABLES        */
/*****************************/


/*****************************/
/*   EXTERNAL VARIABLES      */
/*****************************/


/*****************************/
/*   LOCAL DEFINES           */
/*****************************/

#define NUM_FLOW_RATES 6

/*****************************/
/*   STATIC VARIABLES        */
/*****************************/


/*****************************/
/*   IMPLEMENT SECTION       */
/*****************************/
/**begin_proto**/

#pragma SECTION PROG=rom3

/**end_proto**/



/***********************************************************************/
/* FUNCTION: CalcColumnP()                                             */
/* ========                                                            */
/*                                                                     */
/* PURPOSE: calculate the required values for column head pressure     */
/*          based on the control mode for the column and it's setpt.   */
/*                                                                     */
/*   These values are based on the Oven's Current Temp.                */
/*                                                                     */
/*   Called By the Inlet Control Funtions                              */
/*                                                                     */
/***********************************************************************/

/**begin_proto**/

void CalcColumnP( pCOLUMN_STATUS status, U_INT16 oven_temp )

/**end_proto**/
{

    U_INT32  Pi;
    U_INT16  Po;
    U_INT16  P_25C;

    Po = GetNtpOutletPressure( status );

    switch ( status->Wkfile->Control_Mode )
    {
       case RAMP_FLOW:
                     if ( status->Config->Defined )
                     {
                         Pi = CalcPiFromVFlow ( QuadWordMultiplyDivide( status->Ramp_Setpt.Column_V_Flow,
                                                                        status->IU_Scaling,
                                                                        status->Ramp_Setpt.Ramp_Flow_Scaling ),
                                                oven_temp, Po, status );
                     }
                     else
                     {
                                 /* we can't be calling this if col is undefined */
                         Pi = 0; /* this is just here to keep lint quiet */
                     }
                     break;

       case CONST_FLOW:
                     if ( RampPostValueActive() )
                     {
                         if ( status->Config->Defined )
                         {
                             Pi = CalcPiFromVFlow ( QuadWordMultiplyDivide( status->Ramp_Setpt.Column_V_Flow,
                                                                            status->IU_Scaling,
                                                                            status->Ramp_Setpt.Ramp_Flow_Scaling ),
                                                    oven_temp, Po, status );
                         }
                         else
                         {
                             Pi = QuadWordMultiplyDivide(status->Ramp_Setpt.Head_Pressure,
                                                         status->Ramp_Setpt.Ramp_Pres_Scaling,
                                                         status->Dcm2_Per_IU );
                         }
                     }
                     else
                     {
                         if ( status->Config->Defined )
                         {
                             Pi = CalcPiFromVFlow ( QuadWordMultiplyDivide( status->Ramp_Setpt.Column_V_Flow,
                                                                            status->IU_Scaling,
                                                                            status->Ramp_Setpt.Ramp_Flow_Scaling ),
                                                    oven_temp, Po, status );
                         }
                         else
                         {
                             P_25C = QuadWordMultiplyDivide(status->Ramp_Setpt.Head_Pressure,
                                                            status->Ramp_Setpt.Ramp_Pres_Scaling,
                                                            status->Dcm2_Per_IU );

                             if (status->Config->Vacuum_Comp == ON)
                             {
                                  Pi = CalcPiFromPrevWVC( status, oven_temp, P_25C );
                             }
                             else
                             {
                                  Pi = CalcPiFromPrevWOVC( status, oven_temp, P_25C );
                             }
                         }
                     }
                     break;

       case CONST_PRES:
                     if ( RampPostValueActive() )
                     {
                         Pi = QuadWordMultiplyDivide(status->Ramp_Setpt.Head_Pressure,
                                                     status->Ramp_Setpt.Ramp_Pres_Scaling,
                                                     status->Dcm2_Per_IU );
                     }
                     else
                     {
                         Pi = QuadWordMultiplyDivide(GetRampInitValue( status->Ramp_Info ),
                                                     status->Ramp_Setpt.Ramp_Pres_Scaling,
                                                     status->Dcm2_Per_IU );
                     }
                     break;

       case RAMP_PRES:   Pi = QuadWordMultiplyDivide(status->Ramp_Setpt.Head_Pressure,
                                                     status->Ramp_Setpt.Ramp_Pres_Scaling,
                                                     status->Dcm2_Per_IU );
                     break;

       default:    PneuFatalError (0, BAD_PNEU_CONTROL_MODE );
                   Pi = 0; /* keep lint happy */

    } /* switch */

    status->Desired_Head_Pressure = Pi;

}


/**begin_proto**/

U_INT16 CalcColumnInitP( pCOLUMN_STATUS status )

/**end_proto**/
{

   /* used by column calib routines */

    U_INT32  Pi;
    U_INT16  Po;
    U_INT16  P_25C;
    U_INT16  oven_temp;

    Po = GetNtpOutletPressure( status );

    /* Get the current oven temp and convert to 64ths degree K */
    oven_temp = GetOvenInitTemp();

    switch ( status->Wkfile->Control_Mode )
    {
       case RAMP_FLOW:
                     if ( status->Config->Defined )
                     {
                         Pi = CalcPiFromVFlow ( QuadWordMultiplyDivide( GetRampInitValue(  status->Ramp_Info ),
                                                                        status->IU_Scaling,
                                                                        status->Ramp_Setpt.Ramp_Flow_Scaling ),
                                                oven_temp, Po, status );
                     }
                     else
                     {
                                 /* we can't be calling this if col is undefined */
                         Pi = 0; /* this is just here to keep lint quiet */
                     }
                     break;

       case CONST_FLOW:
                     if ( status->Config->Defined )
                     {
                         Pi = CalcPiFromVFlow ( QuadWordMultiplyDivide( GetRampInitValue(  status->Ramp_Info ),
                                                                        status->IU_Scaling,
                                                                        status->Ramp_Setpt.Ramp_Flow_Scaling ),
                                                oven_temp, Po, status );
                     }
                     else
                     {
                         P_25C = QuadWordMultiplyDivide(status->Ramp_Setpt.Head_Pressure,
                                                        status->Ramp_Setpt.Ramp_Pres_Scaling,
                                                        status->Dcm2_Per_IU );

                         if (status->Config->Vacuum_Comp == ON)
                         {
                             Pi = CalcPiFromPrevWVC( status, oven_temp, P_25C );
                         }
                         else
                         {
                             Pi = CalcPiFromPrevWOVC( status, oven_temp, P_25C );
                         }
                     }
                     break;

       case RAMP_PRES:
       case CONST_PRES:
                     Pi = QuadWordMultiplyDivide(GetRampInitValue(  status->Ramp_Info ),
                                                 status->Ramp_Setpt.Ramp_Pres_Scaling,
                                                 status->Dcm2_Per_IU );
                     break;

       default:    PneuFatalError (0, BAD_PNEU_CONTROL_MODE );
                   Pi = 0; /* keep lint happy */

    } /* switch */

    return  Pi;

}


/***********************************************************************/
/* FUNCTION: CalcColumnF()                                             */
/* ========                                                            */
/*                                                                     */
/* PURPOSE: calculate the required values for column flow              */
/*          based on the control mode for the column and it's setpt.   */
/*                                                                     */
/*   These values are based on the Oven's Current Temp.                */
/*                                                                     */
/*   Called By the Inlet Control Funtions                              */
/*                                                                     */
/***********************************************************************/

/**begin_proto**/

void CalcColumnF( pCOLUMN_STATUS status, U_INT16 oven_temp )

/**end_proto**/
{

    switch ( status->Wkfile->Control_Mode )
    {
        case CONST_FLOW: status->Desired_Column_Flow = QuadWordMultiplyDivide( GetRampInitValue( status->Ramp_Info ),
                                                                               status->IU_Scaling,
                                                                               status->Ramp_Setpt.Ramp_Flow_Scaling );
                         break;

        case RAMP_FLOW:  status->Desired_Column_Flow = QuadWordMultiplyDivide( status->Ramp_Setpt.Column_V_Flow,
                                                                               status->IU_Scaling,
                                                                               status->Ramp_Setpt.Ramp_Flow_Scaling );
                         break;

        case CONST_PRES: if ( status->Config->Defined )
                         {
                             status->Desired_Column_Flow = CalcVFlow( status,
                                                                      oven_temp,
                                                                      QuadWordMultiplyDivide(
                                                                               GetRampInitValue( status->Ramp_Info ),
                                                                               status->Ramp_Setpt.Ramp_Pres_Scaling,
                                                                               status->Dcm2_Per_IU ),
                                                                      GetNtpOutletPressure( status ) );
                         }
                         else
                         {
                              PneuFatalError (0, BAD_PNEU_CONTROL_MODE );
                         }
                         break;

        case RAMP_PRES:  if ( status->Config->Defined )
                         {
                             status->Desired_Column_Flow = CalcVFlow( status,
                                                                      oven_temp,
                                                                      QuadWordMultiplyDivide(
                                                                               status->Ramp_Setpt.Head_Pressure,
                                                                               status->Ramp_Setpt.Ramp_Pres_Scaling,
                                                                               status->Dcm2_Per_IU ),
                                                                      GetNtpOutletPressure( status ) );
                             break;
                         }
                    /* intentional fall through */

        default:    PneuFatalError (0, BAD_PNEU_CONTROL_MODE );

    } /* switch */

}

/***********************************************************************/
/* FUNCTION: FindSourcePressureWithColumns                             */
/* ========                                                            */
/*                                                                     */
/* PURPOSE: Find the pressure the source should be at.                 */
/*                                                                     */
/* RETURNED VALUE: desired source pressure (guage)                     */
/*                                                                     */
/***********************************************************************/
/**begin_proto**/

U_INT16  FindSourcePressureWithColumns ( SOURCE_CONNECTION source, U_INT16 p_scale, U_INT16 oven_temp )

/**end_proto**/
{
    U_INT16 Pi;
    U_INT16 c_scale;

       if ( Inst_Config.Pneu.Column_1.Source == source )
       {
           if ( Inst_Config.Pneu.Column_2.Source == source )
           {
              /* Both columns come from this inlet,  Column 1 always   */
              /* overides column 2. So, use the setpoints for column 1 */
              CalcColumnP( &Inst_Status.Pneu.Column_1, oven_temp );
              Pi = Inst_Status.Pneu.Column_1.Desired_Head_Pressure;
              c_scale = Inst_Status.Pneu.Column_1.Dcm2_Per_IU;
           }
           else
           {
                 CalcColumnP( &Inst_Status.Pneu.Column_1, oven_temp );
                 Pi = Inst_Status.Pneu.Column_1.Desired_Head_Pressure;
                 c_scale = Inst_Status.Pneu.Column_1.Dcm2_Per_IU;
           }
       }
       else
       {
            CalcColumnP( &Inst_Status.Pneu.Column_2, oven_temp );
            Pi = Inst_Status.Pneu.Column_2.Desired_Head_Pressure;
            c_scale = Inst_Status.Pneu.Column_2.Dcm2_Per_IU;
       }

     return (U_INT32)Pi * c_scale / p_scale;
}

/***********************************************************************/
/* FUNCTION: GetTotalColumnFlow                                        */
/* ========                                                            */
/*                                                                     */
/* PURPOSE: Calculate the total column flow for all columns connected  */
/*          to a source if the source pressure is Pi at oven_temp      */
/*                                                                     */
/* RETURNED VALUE: total column flow scaled to specified iu_scaling    */
/*                                                                     */
/***********************************************************************/
/**begin_proto**/

U_INT32 GetTotalColumnF( SOURCE_CONNECTION source, U_INT32 iu_scaling, U_INT16 oven_temp )

/**end_proto**/
{

     U_INT32 column_1_flow = 0L;
     U_INT32 column_2_flow = 0L;

       /* Now that we have the inlet pressure, calulate the column flows at that pressure */

       if ( Inst_Config.Pneu.Column_1.Source == source )
       {
           CalcColumnF( &Inst_Status.Pneu.Column_1, oven_temp );
           column_1_flow = QuadWordMultiplyDivide ( Inst_Status.Pneu.Column_1.Desired_Column_Flow,
                                                    iu_scaling,
                                                    Inst_Status.Pneu.Column_1.IU_Scaling );
       }

       if ( Inst_Config.Pneu.Column_2.Source == source )
       {
           CalcColumnF( &Inst_Status.Pneu.Column_2, oven_temp );
           column_2_flow = QuadWordMultiplyDivide ( Inst_Status.Pneu.Column_2.Desired_Column_Flow,
                                                    iu_scaling,
                                                    Inst_Status.Pneu.Column_2.IU_Scaling );
       }
       /* Revisit: this may have blown beyond the flow sensor's range */

      return column_1_flow + column_2_flow;
}

/**begin_proto**/

U_INT32 GetCol1F( SOURCE_CONNECTION source, U_INT32 iu_scaling, U_INT32 max, BIT8 *ovf, U_INT16 oven_temp )

/**end_proto**/
{

     U_INT32 column_1_flow = 0L;

       /* Now that we have the inlet pressure, calulate the column flows at that pressure */

       if ( Inst_Config.Pneu.Column_1.Source == source )
       {
           CalcColumnF( &Inst_Status.Pneu.Column_1, oven_temp );
           column_1_flow = BoundsCheckedQWMD      ( Inst_Status.Pneu.Column_1.Desired_Column_Flow,
                                                    iu_scaling,
                                                    Inst_Status.Pneu.Column_1.IU_Scaling,
                                                    max,
                                                    ovf );
           if ( *ovf )
           {
               return max;
           }
       }

     return column_1_flow;

}

/**begin_proto**/

U_INT32 GetCol2F( SOURCE_CONNECTION source, U_INT32 iu_scaling, U_INT32 max, BIT8 *ovf, U_INT16 oven_temp )

/**end_proto**/
{

     U_INT32 column_2_flow = 0L;

       /* Now that we have the inlet pressure, calulate the column flows at that pressure */

       if ( Inst_Config.Pneu.Column_2.Source == source )
       {
           CalcColumnF( &Inst_Status.Pneu.Column_2, oven_temp );
           column_2_flow = BoundsCheckedQWMD      ( Inst_Status.Pneu.Column_2.Desired_Column_Flow,
                                                    iu_scaling,
                                                    Inst_Status.Pneu.Column_2.IU_Scaling,
                                                    max,
                                                    ovf );
           if ( *ovf )
           {
               return max;
           }
       }

     return column_2_flow;

}


/***********************************************************************/
/* FUNCTION:                                                           */
/* ========                                                            */
/*                                                                     */
/* PURPOSE:                                                            */
/*                                                                     */
/* RETURNED VALUE:                                                     */
/*                                                                     */
/* GLOBALS USED:                                                       */
/*                                                                     */
/***********************************************************************/
/**begin_proto**/

U_INT32 GetTotalColumnFlowActual( SOURCE_CONNECTION source, U_INT32 iu_scaling )

/**end_proto**/
{

     U_INT32 column_1_flow = 0L;
     U_INT32 column_2_flow = 0L;

       /* Now that we have the inlet pressure, calulate the column flows at that pressure */

       if ( Inst_Config.Pneu.Column_1.Source == source )
       {
           column_1_flow = QuadWordMultiplyDivide ( Inst_Status.Pneu.Column_1.NTP_Adjusted_Current_Flow,
                                                    iu_scaling,
                                                    Inst_Status.Pneu.Column_1.IU_Scaling );
       }

       if ( Inst_Config.Pneu.Column_2.Source == source )
       {
           column_2_flow = QuadWordMultiplyDivide ( Inst_Status.Pneu.Column_2.NTP_Adjusted_Current_Flow,
                                                    iu_scaling,
                                                    Inst_Status.Pneu.Column_2.IU_Scaling );
       }

      return column_1_flow + column_2_flow;
}

/***********************************************************************/
/* FUNCTION:                                                           */
/* ========                                                            */
/*                                                                     */
/* PURPOSE:                                                            */
/*                                                                     */
/* RETURNED VALUE:                                                     */
/*                                                                     */
/* GLOBALS USED:                                                       */
/*                                                                     */
/***********************************************************************/
/**begin_proto**/

void OverideColumnSetpt ( U_INT16 pres, pCOLUMN_STATUS status, U_INT16 p_scale )

/**end_proto**/
{

   status->Active_Pressure = (U_INT32)pres * p_scale / status->Dcm2_Per_IU;

}

/**begin_proto**/

void OverideColumnFlowSetpt ( U_INT32 flow, pCOLUMN_STATUS status, U_INT32 iu_scaling, U_INT8 delay1, U_INT8 delay2 )

/**end_proto**/
{

   Filter32Bits( &status->Intermediate_Flow,  QuadWordMultiplyDivide( flow, status->IU_Scaling, iu_scaling ), delay1 );
   Filter32Bits( &status->Active_Flow,  status->Intermediate_Flow, delay2 );

}

void OverrideSourceActualTemp( pCOLUMN_STATUS status )
{
     switch ( status->Config->Source )
     {
     case FRNT_INLET:  Inst_Status.Pneu.Frnt_Inlet.Ready.Pres.Temp_Exceeds_CF_Max     = TRUE;
                       break;
     case BACK_INLET:  Inst_Status.Pneu.Back_Inlet.Ready.Pres.Temp_Exceeds_CF_Max     = TRUE;
                       break;
     case AUX_3:       Inst_Status.Pneu.Aux.Aux_3.Ready.Temp_Exceeds_CF_Max     = TRUE;
                       break;
     case AUX_4:       Inst_Status.Pneu.Aux.Aux_4.Ready.Temp_Exceeds_CF_Max     = TRUE;
                       break;
     case AUX_5:       Inst_Status.Pneu.Aux.Aux_5.Ready.Temp_Exceeds_CF_Max     = TRUE;
                       break;
     }
}


void ResetOverTempFlags( pCOLUMN_STATUS status )
{
     switch ( status->Config->Source )
     {
     case FRNT_INLET:  Inst_Status.Pneu.Frnt_Inlet.Ready.Pres.Temp_Exceeds_CF_Max     = FALSE;
                       break;
     case BACK_INLET:  Inst_Status.Pneu.Back_Inlet.Ready.Pres.Temp_Exceeds_CF_Max     = FALSE;
                       break;
     case AUX_3:       Inst_Status.Pneu.Aux.Aux_3.Ready.Temp_Exceeds_CF_Max     = FALSE;
                       break;
     case AUX_4:       Inst_Status.Pneu.Aux.Aux_4.Ready.Temp_Exceeds_CF_Max     = FALSE;
                       break;
     case AUX_5:       Inst_Status.Pneu.Aux.Aux_5.Ready.Temp_Exceeds_CF_Max     = FALSE;
                       break;
     }
}


/***********************************************************************/
/* FUNCTION:                                                           */
/* ========                                                            */
/*                                                                     */
/* PURPOSE:                                                            */
/*                                                                     */
/* RETURNED VALUE:                                                     */
/*                                                                     */
/* GLOBALS USED:                                                       */
/*                                                                     */
/***********************************************************************/
/**begin_proto**/

void CalcColNtpAndRealValue ( U_INT16 NTP_Pi, U_INT16 Real_Pi, pCOLUMN_STATUS status, U_INT16 oven_temp )

/**end_proto**/
{
   U_INT16 NTP_Po;
   U_INT16 Po;

   NTP_Po = GetNtpOutletPressure( status );

   status->NTP_Pres_Setpt = NTP_Pi;
   status->NTP_Flow_Setpt = CalcVFlow( status, oven_temp, NTP_Pi, NTP_Po );
   status->NTP_Uavg_Setpt = CalcUavg ( status, oven_temp, NTP_Pi, NTP_Po );

   Po = GetOutletPressure( status );

   status->Pres_Setpt = Real_Pi;
   status->Flow_Setpt = CalcVFlow( status, oven_temp, Real_Pi, Po );
   status->Uavg_Setpt = CalcUavg ( status, oven_temp, Real_Pi, Po );

}


/***********************************************************************/
/* FUNCTION:                                                           */
/* ========                                                            */
/*                                                                     */
/* PURPOSE:                                                            */
/*                                                                     */
/* RETURNED VALUE:                                                     */
/*                                                                     */
/* GLOBALS USED:                                                       */
/*                                                                     */
/***********************************************************************/
/**begin_proto**/

void CalcColNtpAndRealActuals ( U_INT16 NTP_Pi, U_INT16 Real_Pi, pCOLUMN_STATUS status, U_INT16 oven_temp )

/**end_proto**/
{
   U_INT16 Po;

   status->Pres_Actual = Real_Pi;
   status->Flow_Actual = CalcVFlow( status, oven_temp, Real_Pi, status->Ref_Po );
   status->Uavg_Actual = CalcUavg ( status, oven_temp, Real_Pi, status->Ref_Po );


   Po = GetNtpOutletPressure( status );

   status->NTP_Adjusted_Current_Pressure = NTP_Pi;
   status->NTP_Pres_Actual = NTP_Pi;
   status->NTP_Flow_Actual = CalcVFlow( status, oven_temp, NTP_Pi, Po );
   status->NTP_Uavg_Actual = CalcUavg ( status, oven_temp, NTP_Pi, Po );
}


/***********************************************************************/
/* FUNCTION:                                                           */
/* ========                                                            */
/*                                                                     */
/* PURPOSE:                                                            */
/*                                                                     */
/* RETURNED VALUE:                                                     */
/*                                                                     */
/* GLOBALS USED:                                                       */
/*                                                                     */
/***********************************************************************/
/**begin_proto**/

U_INT16 CorrectForAtmospheric ( U_INT16 NTP_Pi, SOURCE_CONNECTION source, U_INT32 *correct_ratio, U_INT16 oven_temp, BIT8 calc_new_reference, BIT8 over_ridden )

/**end_proto**/
{

   U_INT16        Pi, Po, NTP_Po;
   pCOLUMN_STATUS status;
   RAMP_FLAG      ramp_state;
   U_INT32        NTP_Flow;



   if ( Inst_Config.Pneu.Column_1.Source == source )
   {
       status = &Inst_Status.Pneu.Column_1;
   }
   else
   {
       status = &Inst_Status.Pneu.Column_2;
   }


   NTP_Po = GetNtpOutletPressure( status );

   status->NTP_Pres_Setpt = NTP_Pi;
   NTP_Flow = status->NTP_Flow_Setpt = CalcVFlow( status, oven_temp, NTP_Pi, NTP_Po );
   status->NTP_Uavg_Setpt = CalcUavg ( status, oven_temp, NTP_Pi, NTP_Po );

   Po = GetOutletPressure( status );

   if ( status->Atm_Pres_Comp_Enabled == TRUE )
   {
        if (( status->Wkfile->Control_Mode == CONST_PRES ) || ( over_ridden ) )
        {
             if (( calc_new_reference ) || ( status->Periodic_Update_Request ))
             {
                  status->Real_Ref_Pres = CalcPiFromUavg ( status->NTP_Uavg_Setpt, oven_temp, Po, status );
                  status->Ref_Po        = Po;
             }
             Pi = status->Real_Ref_Pres;
        }
        else
        {
             switch ( status->Wkfile->Control_Mode )
             {

                case CONST_FLOW: if (( calc_new_reference ) || ( status->Periodic_Update_Request ))
                                 {
                                      Pi = CalcPiFromUavg ( status->NTP_Uavg_Setpt, oven_temp, Po, status );
                                      status->Real_Ref_Flow = CalcVFlow( status, oven_temp, Pi, Po );
                                      status->Ref_Po  = Po;
                                      status->Max_Oven_Temp = CalcTempFromVFlow (status->Real_Ref_Flow,
                                                                                 GetSourceRealMaxPresIu( status),
                                                                                 Po,
                                                                                 status );
                                 }

                                 if ( oven_temp > status->Max_Oven_Temp )
                                 {
                                      oven_temp = status->Max_Oven_Temp;
                                      OverrideSourceActualTemp( status );
                                      NTP_Flow  = CalcVFlow( status,
                                                             oven_temp,
                                                             GetSourceMaxPresIu( status ),
                                                             NTP_Po );
                                 }
                                 else
                                 {
                                      ResetOverTempFlags( status );
                                 }

                                 Pi = CalcPiFromVFlow( status->Real_Ref_Flow, oven_temp, Po, status );

                                 break;

                case RAMP_PRES:  if (( calc_new_reference ) ||
                                     ( status->Periodic_Update_Request ) ||
                                     ( GetRampState( (pRAMPINFO)status->Ramp_Info ) == RAMP ) )
                                 {
                                      status->Real_Ref_Pres = CalcPiFromUavg( status->NTP_Uavg_Setpt, oven_temp, Po, status);
                                      status->Ref_Po  = Po;
                                 }
                                 Pi = status->Real_Ref_Pres;
                                 break;

                case RAMP_FLOW:  ramp_state = GetRampState( (pRAMPINFO)status->Ramp_Info );

                                 if (( calc_new_reference ) ||
                                     ( status->Periodic_Update_Request ) ||
                                     ( ramp_state == RAMP ) )
                                 {
                                      Pi = CalcPiFromUavg ( status->NTP_Uavg_Setpt, oven_temp, Po, status );
                                      status->Real_Ref_Flow = CalcVFlow( status, oven_temp, Pi, Po );
                                      status->Ref_Po  = Po;

                              /*      if ( ramp_state != RAMP )   */
                                      {
                                          status->Max_Oven_Temp = CalcTempFromVFlow (status->Real_Ref_Flow,
                                                                                     GetSourceRealMaxPresIu( status),
                                                                                     Po,
                                                                                     status );
                                      }
                                 }

                                 if ( ( ramp_state != RAMP ) &&
                                      ( oven_temp > status->Max_Oven_Temp ) )
                                 {
                                      oven_temp = status->Max_Oven_Temp;
                                      OverrideSourceActualTemp( status );
                                      status->NTP_Flow_Setpt = CalcVFlow( status,
                                                                          oven_temp,
                                                                          GetSourceMaxPresIu( status ),
                                                                          NTP_Po );
                                 }
                                 else
                                 {
                                      ResetOverTempFlags( status );
                                 }

                                 Pi = CalcPiFromVFlow( status->Real_Ref_Flow, oven_temp, Po, status );
                                 /* revisit, somehow need to cap this, it can overflow the ps range */
                                 break;

               default:          Pi = CalcPiFromUavg ( status->NTP_Uavg_Setpt, oven_temp, Po, status );
                                 break;
             }
        }

        if ( Pi > GetSourceRealMaxPresIu( status ))
        {
              Pi = GetSourceRealMaxPresIu( status );
              NTP_Flow = CalcVFlow( status, oven_temp, GetSourceMaxPresIu( status ), NTP_Po );
        }

        status->Periodic_Update_Request = FALSE;
   }
   else
   {
         Pi = NTP_Pi;
         status->Ref_Po = NTP_Po;
   }

   status->Pres_Setpt = Pi;
   status->Flow_Setpt = CalcVFlow( status, oven_temp, Pi, Po );
   status->Uavg_Setpt = CalcUavg ( status, oven_temp, Pi, Po );

   if ( status->Flow_Setpt != 0 )
   {
       *correct_ratio = QuadWordMultiplyDivide( NTP_Flow, ATMP_FLOW_CORRECT_SCALING, status->Flow_Setpt );
   }
   else
   {
       *correct_ratio = ATMP_FLOW_CORRECT_SCALING;
   }

   if (( Inst_Config.Pneu.Column_1.Source == source ) &&
       ( Inst_Config.Pneu.Column_2.Source == source ))
   {
        Inst_Status.Pneu.Column_2.Ref_Po = status->Ref_Po;
        CalcColNtpAndRealValue ( NTP_Pi, Pi, &Inst_Status.Pneu.Column_2, oven_temp );
   }

   return Pi;
}


/***********************************************************************/
/* FUNCTION:                                                           */
/* ========                                                            */
/*                                                                     */
/* PURPOSE:                                                            */
/*                                                                     */
/* RETURNED VALUE:                                                     */
/*                                                                     */
/* GLOBALS USED:                                                       */
/*                                                                     */
/***********************************************************************/
/**begin_proto**/

U_INT16 CorrectToNTP ( U_INT16 Pi, SOURCE_CONNECTION source, U_INT32 *actual_correct_ratio, U_INT16 oven_temp, U_INT32 setpt_correct_ratio )

/**end_proto**/
{

   U_INT16    NTP_Po;
   U_INT16    NTP_Pi;
   pCOLUMN_STATUS status;

   if ( Inst_Config.Pneu.Column_1.Source == source )
   {
       status = &Inst_Status.Pneu.Column_1;
   }
   else
   {
       status = &Inst_Status.Pneu.Column_2;
   }

   if ( ! status->Config->Defined ) return Pi;

   status->Pres_Actual = Pi;
   status->Flow_Actual = CalcVFlow( status, oven_temp, Pi, GetOutletPressure(status) /*status->Ref_Po*/ );
   status->Uavg_Actual = CalcUavg ( status, oven_temp, Pi, GetOutletPressure(status) /*status->Ref_Po*/ );

   NTP_Po = GetNtpOutletPressure( status );

   if ( status->Atm_Pres_Comp_Enabled == TRUE )
   {
        switch ( status->Wkfile->Control_Mode )
        {
           case CONST_FLOW: NTP_Pi = CalcPiFromVFlow( AdjustFlowToNTP( status->Flow_Actual, setpt_correct_ratio),
                                                  oven_temp, NTP_Po, status );
                            break;

           case RAMP_FLOW:  if ( GetRampState( (pRAMPINFO)status->Ramp_Info ) != RAMP )
                            {
                                NTP_Pi = CalcPiFromVFlow( AdjustFlowToNTP( status->Flow_Actual, setpt_correct_ratio),
                                                  oven_temp, NTP_Po, status );
                            }
                            else
                            {
                                NTP_Pi = CalcPiFromUavg ( status->Uavg_Actual, oven_temp, NTP_Po, status );
                            }
                            break;

           default:         NTP_Pi = CalcPiFromUavg ( status->Uavg_Actual, oven_temp, NTP_Po, status );
                            break;
        }
   }
   else
   {
      NTP_Pi = Pi;
   }


   status->NTP_Pres_Actual = NTP_Pi;
   status->NTP_Flow_Actual = CalcVFlow( status, oven_temp, NTP_Pi, NTP_Po );
   status->NTP_Uavg_Actual = CalcUavg ( status, oven_temp, NTP_Pi, NTP_Po );

   if ( status->Flow_Actual != 0 )
   {
       *actual_correct_ratio = QuadWordMultiplyDivide( status->NTP_Flow_Actual,
                                                       ATMP_FLOW_CORRECT_SCALING,
                                                       status->Flow_Actual );
   }
   else
   {
       *actual_correct_ratio = ATMP_FLOW_CORRECT_SCALING;
   }

   if (( Inst_Config.Pneu.Column_1.Source == source ) &&
       ( Inst_Config.Pneu.Column_2.Source == source ))
   {
        CalcColNtpAndRealActuals( NTP_Pi, Pi, &Inst_Status.Pneu.Column_2, oven_temp );
   }

   return NTP_Pi;
}


/***********************************************************************/
/* FUNCTION:                                                           */
/* ========                                                            */
/*                                                                     */
/* PURPOSE:                                                            */
/*                                                                     */
/* RETURNED VALUE:                                                     */
/*                                                                     */
/* GLOBALS USED:                                                       */
/*                                                                     */
/***********************************************************************/
/**begin_proto**/

U_INT32 AdjustFlowToNTP( U_INT32 flow, U_INT32 correct_ratio )

/**end_proto**/
{
#if 1
    return QuadWordMultiplyDivide( flow, correct_ratio, ATMP_FLOW_CORRECT_SCALING );
#else
    return QuadWordMultiplyDivide( flow, ATMP_FLOW_CORRECT_SCALING, correct_ratio );
#endif
}

/***********************************************************************/
/* FUNCTION:                                                           */
/* ========                                                            */
/*                                                                     */
/* PURPOSE:                                                            */
/*                                                                     */
/* RETURNED VALUE:                                                     */
/*                                                                     */
/* GLOBALS USED:                                                       */
/*                                                                     */
/***********************************************************************/
/**begin_proto**/

U_INT32 AdjustNtpFlow( U_INT32 flow, U_INT32 correct_ratio )

/**end_proto**/
{
    return QuadWordMultiplyDivide( flow, ATMP_FLOW_CORRECT_SCALING, correct_ratio );
}

/***********************************************************************/
/* FUNCTION:  CalcColumnActuals                                        */
/* ========                                                            */
/*                                                                     */
/* PURPOSE:   Based on inlet or aux pressures calced from adc readings */
/*            calculate the columns current actuals                    */
/*                                                                     */
/*   Actuals are based on the Oven's Current Temp.                     */
/*                                                                     */
/*   Called by the pneu display module                                 */
/*                                                                     */
/***********************************************************************/
/**begin_proto**/

void CalcColumnActuals ( pCOLUMN_STATUS status, U_INT16 oven_temp )

/**end_proto**/

{

      U_INT32 purge_flow;
      U_INT32 inlet_flow;
      U_INT32 ntp_inlet_flow;
      U_INT32 other_col_flow;
      U_INT32 other_col_ntp_flow;
      U_INT16 ntp_pres;
      U_INT16 pres;
      U_INT16 p_scale;

      switch ( status->Config->Source )
      {
          case FRNT_INLET: pres     = Inst_Status.Pneu.Frnt_Inlet.Filtered_Current_Pressure;
                           ntp_pres = Inst_Status.Pneu.Frnt_Inlet.NTP_Adjusted_Current_Pressure;
                           p_scale  = Inst_Status.Pneu.Frnt_Inlet.Dcm2_Per_IU;
                           break;
          case BACK_INLET: pres     = Inst_Status.Pneu.Back_Inlet.Filtered_Current_Pressure;
                           ntp_pres = Inst_Status.Pneu.Back_Inlet.NTP_Adjusted_Current_Pressure;
                           p_scale  = Inst_Status.Pneu.Back_Inlet.Dcm2_Per_IU;
                           break;
          case AUX_3:      pres     = Inst_Status.Pneu.Aux.Aux_3.Filtered_Current_Pressure;
                           ntp_pres = Inst_Status.Pneu.Aux.Aux_3.NTP_Adjusted_Current_Pressure;
                           p_scale  = Inst_Status.Pneu.Aux.Aux_3.Dcm2_Per_IU;
                           break;
          case AUX_4:      pres     = Inst_Status.Pneu.Aux.Aux_4.Filtered_Current_Pressure;
                           ntp_pres = Inst_Status.Pneu.Aux.Aux_4.NTP_Adjusted_Current_Pressure;
                           p_scale  = Inst_Status.Pneu.Aux.Aux_4.Dcm2_Per_IU;
                           break;
          case AUX_5:      pres     = Inst_Status.Pneu.Aux.Aux_5.Filtered_Current_Pressure;
                           ntp_pres = Inst_Status.Pneu.Aux.Aux_5.NTP_Adjusted_Current_Pressure;
                           p_scale  = Inst_Status.Pneu.Aux.Aux_5.Dcm2_Per_IU;
                           break;
          default:         pres = 0; ntp_pres = 0; p_scale = 1;
      }

      status->Current_Head_Pressure         = (U_INT32) pres     * p_scale / status->Dcm2_Per_IU;
      status->NTP_Adjusted_Current_Pressure = (U_INT32) ntp_pres * p_scale / status->Dcm2_Per_IU;

      if ( status->Config->Defined )
      {
          status->Current_V_Flow            = CalcVFlow ( status,
                                                          oven_temp,
                                                          status->Current_Head_Pressure,
                                                          GetOutletPressure ( status ) );
          status->NTP_Adjusted_Current_Flow = CalcVFlow ( status,
                                                          oven_temp,
                                                          status->NTP_Adjusted_Current_Pressure,
                                                          GetNtpOutletPressure ( status ));
      }
      else
      {
          /* undefined columns require PP inlets to be flow controlled */
          /* and since the column screen wants an actual column flow   */
          /* we have this kludge calculation here.                     */

          if (( GetColSourceType ( status ) == PP_INLET ) || (GetColSourceType ( status ) == ACI_INLET     )
                                                          || (GetColSourceType ( status ) == SIMDIST_INLET )
                                                          || ( VIFlowSourceChk ( status )                  )  )
          {
               switch ( status->Config->Source )
               {
                  case FRNT_INLET: inlet_flow     = QuadWordMultiplyDivide(
                                                         Inst_Status.Pneu.Frnt_Inlet.Filtered_Current_Total_Flow,
                                                         status->IU_Scaling,
                                                         Inst_Status.Pneu.Frnt_Inlet.IU_Scaling );

                                   ntp_inlet_flow = QuadWordMultiplyDivide(
                                                         Inst_Status.Pneu.Frnt_Inlet.NTP_Adjusted_Current_Flow,
                                                         status->IU_Scaling,
                                                         Inst_Status.Pneu.Frnt_Inlet.IU_Scaling );
                                   purge_flow     =  QuadWordMultiplyDivide(
                                                         CalcSeptumPurgeFlow ( &Inst_Status.Pneu.Frnt_Inlet,
                                                                    Inst_Status.Pneu.Frnt_Inlet.Filtered_Current_Pressure ),
                                                         status->IU_Scaling,
                                                         Inst_Status.Pneu.Frnt_Inlet.IU_Scaling );
                                   break;
                  case BACK_INLET: inlet_flow     = QuadWordMultiplyDivide(
                                                         Inst_Status.Pneu.Back_Inlet.Filtered_Current_Total_Flow,
                                                         status->IU_Scaling,
                                                         Inst_Status.Pneu.Back_Inlet.IU_Scaling );

                                   ntp_inlet_flow = QuadWordMultiplyDivide(
                                                         Inst_Status.Pneu.Back_Inlet.NTP_Adjusted_Current_Flow,
                                                         status->IU_Scaling,
                                                         Inst_Status.Pneu.Back_Inlet.IU_Scaling );
                                   purge_flow     =  QuadWordMultiplyDivide(
                                                         CalcSeptumPurgeFlow ( &Inst_Status.Pneu.Back_Inlet,
                                                                    Inst_Status.Pneu.Back_Inlet.Filtered_Current_Pressure ),
                                                         status->IU_Scaling,
                                                         Inst_Status.Pneu.Back_Inlet.IU_Scaling );
                                   break;
                  default:         ntp_inlet_flow = inlet_flow = purge_flow = 0; /* just keep lint happy */
               }

               if ( purge_flow >= inlet_flow )
               {
                    status->Current_V_Flow            = 0;
                    status->NTP_Adjusted_Current_Flow = 0;
               }
               else
               {
                   if ( Inst_Config.Pneu.Column_1.Source == Inst_Config.Pneu.Column_2.Source )
                   {
                       if ( Inst_Config.Pneu.Column_1.Defined == Inst_Config.Pneu.Column_2.Defined )
                       {
                            /* neither col is defined, so split flow evenly between columns */
                            status->Current_V_Flow            = (inlet_flow - purge_flow) / 2;
                            status->NTP_Adjusted_Current_Flow = (ntp_inlet_flow - purge_flow) / 2;
                       }
                       else
                       {
                            /* the other column is defined, so it's real column flow is known  */
                            /* and subtracted from inlet flow to find the flow for this column */
                            if ( status->Position == 1 )
                            {
                                /* damn, the other column's flow hasn't been calculated yet, do it now */

                                status = &Inst_Status.Pneu.Column_2;
                                status->Current_V_Flow            = CalcVFlow ( status,
                                                                                oven_temp,
                                                                                status->Current_Head_Pressure,
                                                                                GetOutletPressure ( status ) );
                                status->NTP_Adjusted_Current_Flow = CalcVFlow ( status,
                                                                                oven_temp,
                                                                                status->NTP_Adjusted_Current_Pressure,
                                                                                GetNtpOutletPressure ( status ));
                                status = &Inst_Status.Pneu.Column_1;

                                other_col_flow = QuadWordMultiplyDivide( Inst_Status.Pneu.Column_2.Current_V_Flow,
                                                                         Inst_Status.Pneu.Column_2.IU_Scaling,
                                                                         status->IU_Scaling );

                                other_col_ntp_flow = QuadWordMultiplyDivide( Inst_Status.Pneu.Column_2.NTP_Adjusted_Current_Flow,
                                                             Inst_Status.Pneu.Column_2.IU_Scaling,
                                                             status->IU_Scaling );

                            }
                            else
                            {
                                other_col_flow = QuadWordMultiplyDivide( Inst_Status.Pneu.Column_1.Current_V_Flow,
                                                             Inst_Status.Pneu.Column_1.IU_Scaling,
                                                             status->IU_Scaling );

                                other_col_ntp_flow = QuadWordMultiplyDivide( Inst_Status.Pneu.Column_1.NTP_Adjusted_Current_Flow,
                                                             Inst_Status.Pneu.Column_1.IU_Scaling,
                                                             status->IU_Scaling );
                            }

                            if ( ( inlet_flow - purge_flow ) > other_col_flow )
                            {
                               status->Current_V_Flow = inlet_flow - purge_flow - other_col_flow;
                            }
                            else
                            {
                               /* not enough flow to go around */
                               status->Current_V_Flow = 0;
                            }

                            if ( ( ntp_inlet_flow - purge_flow ) > other_col_ntp_flow )
                            {
                               status->NTP_Adjusted_Current_Flow = ntp_inlet_flow - purge_flow - other_col_ntp_flow;
                            }
                            else
                            {
                               /* not enough flow to go around */
                               status->NTP_Adjusted_Current_Flow = 0;
                            }
                       }
                   }
                   else  /* only one column on this source */
                   {
                       status->Current_V_Flow            = inlet_flow - purge_flow;
                       if ( purge_flow < ntp_inlet_flow ) status->NTP_Adjusted_Current_Flow = ntp_inlet_flow - purge_flow;
                       else                               status->NTP_Adjusted_Current_Flow = 0;
                   }
               }
          }
          else /* NOT a PP type inlet, i.e. COC or other.  Undefined too, so ... */
          {
          /* COC does not have a flow sensor, we can't determine column flows */
          status->NTP_Adjusted_Current_Flow = 0;
          status->Current_V_Flow            = 0;
          }

      }

}

/***********************************************************************/
/* FUNCTION:  GetColumnPresSetptIu                                     */
/* ========                                                            */
/*                                                                     */
/* PURPOSE: return the column head pressure based on it's current      */
/*          control mode and setpt at a specified temp.                */
/*                                                                     */
/* RETURNED VALUE:  Column Head Pressure (guage) in IU                 */
/*                                                                     */
/* Called by interface routines when control mode or configuration     */
/* is changed allowing one to update setpoints.                        */
/*                                                                     */
/***********************************************************************/

/**begin_proto**/

U_INT16 GetColumnPresSetptIu( pCOLUMN_STATUS status, U_INT16 oven_temp )

/**end_proto**/
{

     (void) oven_temp;

    return status->Active_Pressure;


}

/***********************************************************************/
/* FUNCTION: FindTotalColumnFlow                                       */
/* ========                                                            */
/*                                                                     */
/* PURPOSE: Calculate the total column flow for all columns connected  */
/*          to a source if the source pressure is Pi at oven_temp      */
/*                                                                     */
/* RETURNED VALUE: total column flow scaled to specified iu_scaling    */
/*                                                                     */
/***********************************************************************/
/**begin_proto**/

U_INT32 FindTotalColumnFlow ( SOURCE_CONNECTION source, U_INT16 Pi, U_INT16 oven_temp, U_INT32 iu_scaling,
                              U_INT32 max, BIT8 *ovf )

/**end_proto**/
{

     U_INT32 column_1_flow = 0L;
     U_INT32 column_2_flow = 0L;
     U_INT32 column_flow;
     U_INT16 Po;
     pCOLUMN_STATUS status;

       /* Now that we have the inlet pressure, calulate the column flows at that pressure */

           /* small columns will have different internal unit scaling than large */
           /* columns, convert this scaling back to the one used for inlets      */


       if ( Inst_Config.Pneu.Column_1.Source == source )
       {
           status        = &Inst_Status.Pneu.Column_1;
           Po            = GetNtpOutletPressure   ( status );
           column_flow   = CalcVFlow ( status, oven_temp, Pi, Po );
           column_1_flow = BoundsCheckedQWMD ( column_flow, iu_scaling, status->IU_Scaling, max, ovf );
           if ( *ovf )
           {
               return max;
           }
       }

       if ( Inst_Config.Pneu.Column_2.Source == source )
       {
           status        = &Inst_Status.Pneu.Column_2;
           Po            = GetNtpOutletPressure   ( status );
           column_flow   = CalcVFlow ( status, oven_temp, Pi, Po );
           column_2_flow = BoundsCheckedQWMD ( column_flow, iu_scaling, status->IU_Scaling, max, ovf );
           if ( *ovf )
           {
               return max;
           }
       }

       if ( (column_1_flow + column_2_flow ) < column_1_flow )
       {
            *ovf = TRUE;
            return max;
       }

      return column_1_flow + column_2_flow;
}

/***********************************************************************/
/* FUNCTION: CalcTotalColumnFlowNTP                                    */
/* ========                                                            */
/*                                                                     */
/* PURPOSE: Calculate the total column flow for all columns connected  */
/*          to a source if the source pressure is Pi at oven_temp      */
/*                                                                     */
/* RETURNED VALUE: total column flow scaled to specified iu_scaling    */
/*                                                                     */
/***********************************************************************/
/**begin_proto**/

U_INT32 CalcTotalColumnFlowNTP ( SOURCE_CONNECTION source, U_INT16 Pi, U_INT16 oven_temp, U_INT32 iu_scaling )

/**end_proto**/
{

     U_INT32 column_1_flow = 0L;
     U_INT32 column_2_flow = 0L;
     U_INT32 column_flow;
     U_INT16 Po;
     pCOLUMN_STATUS status;

       /* Now that we have the inlet pressure, calulate the column flows at that pressure */

       if ( Inst_Config.Pneu.Column_1.Source == source )
       {
           status        = &Inst_Status.Pneu.Column_1;
           Po            = GetNtpOutletPressure( status );
           column_flow   = CalcVFlow ( status, oven_temp, Pi, Po );
           column_1_flow = QuadWordMultiplyDivide ( column_flow, iu_scaling, status->IU_Scaling );
       }

       if ( Inst_Config.Pneu.Column_2.Source == source )
       {
           status        = &Inst_Status.Pneu.Column_2;
           Po            = GetNtpOutletPressure( status );
           column_flow   = CalcVFlow ( status, oven_temp, Pi, Po );
           column_2_flow = QuadWordMultiplyDivide ( column_flow, iu_scaling, status->IU_Scaling );
       }

      return column_1_flow + column_2_flow;
}

/***********************************************************************/
/* FUNCTION: FindTotalOutletFlow                                       */
/* ========                                                            */
/*                                                                     */
/* PURPOSE: Calculate the total column flow for all columns connected  */
/*          to a outlet if the source pressure is Pi at oven_temp      */
/*                                                                     */
/* RETURNED VALUE: total column flow scaled to specified iu_scaling    */
/*                                                                     */
/***********************************************************************/
/**begin_proto**/

U_INT32 FindTotalOutletFlow ( OUTLET_CONNECTION outlet, U_INT32 iu_scaling )

/**end_proto**/
{

     U_INT32 column_1_flow = 0L;
     U_INT32 column_2_flow = 0L;
     U_INT32 column_flow;

       /* Now that we have the inlet pressure, calulate the column flows at that pressure */

       if ( Inst_Config.Pneu.Column_1.Outlet == outlet )
       {
           column_flow = 0;
           if ( GetColumnSourceState( &Inst_Status.Pneu.Column_1 ) == ON )
           {
              column_flow = Inst_Status.Pneu.Column_1.Current_V_Flow;
           }
           /* small columns will have different internal unit scaling than large */
           /* columns, convert this scaling back to the one used for inlets      */
           column_1_flow = QuadWordMultiplyDivide ( column_flow, iu_scaling, Inst_Status.Pneu.Column_1.IU_Scaling );
       }

       if ( Inst_Config.Pneu.Column_2.Outlet == outlet )
       {
           column_flow = 0;
           if ( GetColumnSourceState( &Inst_Status.Pneu.Column_2 ) == ON )
           {
              column_flow = Inst_Status.Pneu.Column_2.Current_V_Flow;
           }
           /* small columns will have different internal unit scaling than large */
           /* columns, convert this scaling back to the one used for inlets      */
           column_2_flow = QuadWordMultiplyDivide ( column_flow, iu_scaling, Inst_Status.Pneu.Column_2.IU_Scaling );
       }
       /* Revisit: this may have blown beyond the flow sensor's range */

      return column_1_flow + column_2_flow;
}

/***********************************************************************/
/* FUNCTION:                                                           */
/* ========                                                            */
/*                                                                     */
/* PURPOSE: to allow the ramp generator to stuff post and init values  */
/*          into inlet/aux setpt display filters.                      */
/*                                                                     */
/* RETURNED VALUE:                                                     */
/*                                                                     */
/* GLOBALS USED:                                                       */
/*                                                                     */
/***********************************************************************/
/**begin_proto**/

void  SlamColumnSetpt( U_INT32 setpt, pCOLUMN_STATUS status )

/**end_proto**/
{

     U_INT16 pres;
     U_INT32 flow;

     /* when bot cols are connected together, only accept col1 post value */

     if (( status->Position == 2 ) &&
         (Inst_Config.Pneu.Column_1.Source == Inst_Config.Pneu.Column_2.Source )) return;



     if ( GetRampType((pRAMPINFO)GetRampInfoPtr( status )) == PRESSURE_RAMP )
     {
         /* setpt is a pressure value */

         status->Ramp_Setpt.Head_Pressure = setpt;

         pres = QuadWordMultiplyDivide( setpt, status->Ramp_Setpt.Ramp_Pres_Scaling, status->Dcm2_Per_IU );

         status->Desired_Head_Pressure   = pres;
         status->Active_Pressure         = pres;

     }
     else
     {
         /* setpt is a flow value */

         status->Ramp_Setpt.Column_V_Flow = setpt;

         flow = QuadWordMultiplyDivide( setpt, status->IU_Scaling, status->Ramp_Setpt.Ramp_Flow_Scaling );

         status->Desired_Column_Flow     = flow;
         status->Intermediate_Flow       = flow;
         status->Active_Flow             = flow;

     }

     SlamSourceSetpt ( status );

}

/***********************************************************************/
/* FUNCTION:                                                           */
/* ========                                                            */
/*                                                                     */
/* PURPOSE:                                                            */
/*                                                                     */
/* RETURNED VALUE:                                                     */
/*                                                                     */
/* GLOBALS USED:                                                       */
/*                                                                     */
/***********************************************************************/
/**begin_proto**/

void SlamSourceSetpt ( pCOLUMN_STATUS status )

/**end_proto**/
{

     switch ( status->Config->Source )
     {
          case FRNT_INLET:  SlamInletSetpt( &Inst_Status.Pneu.Frnt_Inlet );
                            break;

          case BACK_INLET:  SlamInletSetpt( &Inst_Status.Pneu.Back_Inlet );
                            break;

          case AUX_3:       SlamAuxSetpt( &Inst_Status.Pneu.Aux.Aux_3 );
                            break;

          case AUX_4:       SlamAuxSetpt( &Inst_Status.Pneu.Aux.Aux_4 );
                            break;

          case AUX_5:       SlamAuxSetpt( &Inst_Status.Pneu.Aux.Aux_5 );
                            break;
     }
}

/***********************************************************************/
/* FUNCTION:                                                           */
/* ========                                                            */
/*                                                                     */
/* PURPOSE:                                                            */
/*                                                                     */
/* RETURNED VALUE:                                                     */
/*                                                                     */
/* GLOBALS USED:                                                       */
/*                                                                     */
/***********************************************************************/
/**begin_proto**/

void PeriodicPresCorrect( void )

/**end_proto**/
{

     if ( !RunActiveOrPostTime() )
     {
          Inst_Status.Pneu.Column_1.Periodic_Update_Request = TRUE;
          Inst_Status.Pneu.Column_2.Periodic_Update_Request = TRUE;
     }
}

/**begin_proto**/

#pragma SECTION UNDO

/**end_proto**/
